package cn.js.sangu.unitStore.service;

import cn.js.sangu.unitStore.common.exception.ServiceException;
import cn.js.sangu.unitStore.entity.Audit;
import cn.js.sangu.unitStore.mapper.AuditMapper;
import cn.js.sangu.unitStore.utils.TokenUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Objects;

@Slf4j
@Service
public class AuditService extends ServiceImpl<AuditMapper, Audit> {

    public Audit saveInfo(Audit audit) {
        audit.setUserid(Objects.requireNonNull(TokenUtils.getCurrentUser()).getId());
        if (!super.save(audit)){
            throw new ServiceException("保存失败！请联系管理员");
        }
        return audit;
    }
}
